import { useEffect } from 'react'

import { Keyboard } from 'react-native'
import { useSharedValue, withTiming } from 'react-native-reanimated'

export const useKeyboardAnimation = (props: number = 0) => {
    const keyboardHeight = useSharedValue(props)
    useEffect(() => {
        Keyboard.addListener('keyboardWillShow', (e) => {
            keyboardHeight.value = withTiming(e.endCoordinates.height, {
                duration: 240
            })
        })
        Keyboard.addListener('keyboardWillHide', () => {
            keyboardHeight.value = withTiming(props, {
                duration: 250
            })
        })

        return () => {
            Keyboard.removeAllListeners('keyboardDidShow')
            Keyboard.removeAllListeners('keyboardDidHide')
        }
    }, [])

    return keyboardHeight

}